#ifndef __MYPLUG_H
#define __MYPLUG_H

#include <string.h>
#include "plugin.h"

#define strequal(str1, str2) (!strcmp(str1,str2))

int broadCallback(int windowID, char *subwindow, char *event, void *data, void *userData);

//BasePlugin implements base fuctionality of Trillian Plugin.
class BasePlugin{
	//callback for broadcast messages
	friend int broadCallback(int windowID, char *subwindow, char *event, void *data, void *userData);
public:
	BasePlugin();
	virtual ~BasePlugin();
	
	//is called when plugin is loaded
	virtual void Load(plugin_info_t* plugin_info);
	
	//is called when plugin is unloaded
	virtual void Unload();
	
	//is called when lugin is loaded for first time (when it is enabled in preferences)
	virtual void InitialLoad();
	
	//is called when plugin is disabled in preferences
	virtual void FinalUnload();

	//is called when plugin should start - good place to read cfg, subscribe for events, etc
	virtual void Start();
	
	//is called when plugin should stop. good place to unsubscribe from events, etc. 
	//unsubscribing is done automaticalli in this class
	virtual void Stop();
protected:
	//sends command to plugin
	int Send(char* command, void* data);
	
	//subscribes for broadcast messages
	int EnableBroadcast();
	
	//unsubscribes from broadcast messages
	int DisableBroadcast();
	
	//is called when any broadcast message is received
	virtual int OnBroadcast(int windowID, char *subwindow, char *event, message_t* msg);
	
	//tells Trillian that new message is received
	int CMDReceive(char* medium, int connection_id, char* name, char* type, char* text, int window_id, unsigned int time_stamp);

	//should return guid
	virtual char* GetGUID()=0;
	
	//should return plugin name
	virtual const char* GetName();
	
	//should return plugin company
	virtual const char* GetCompany();
	
	//should return plugin version
	virtual const char* GetVersion();
	
	//should return plugin description
	virtual const char* GetDescription();

	//returns true is specified message is incoming private, false otherwise
	bool IsIncomingPrivateMessage(message_t* msg);

private:
	int _broadcast_id;
	char*						_home_directory;
	plugin_function_send		_plugin_send;
};
#endif